(module
  (type $ft (func))
  (type $st (struct))
  (type $at (array i8))

  (table 10 anyref)

  (elem declare func $f)
  (func $f)

  (func (export "init") (param $x externref)
    (table.set (i32.const 0) (ref.null any))
    (table.set (i32.const 1) (i31.new (i32.const 7)))
    (table.set (i32.const 2) (struct.new_default $st (rtt.canon $st)))
    (table.set (i32.const 3) (array.new_default $at (i32.const 0) (rtt.canon $at)))
    (table.set (i32.const 4) (ref.func $f))
    (table.set (i32.const 5) (rtt.canon $ft))
    (table.set (i32.const 6) (local.get $x))
  )

  (func (export "ref_is_null") (param $i i32) (result i32)
    (ref.is_null (table.get (local.get $i)))
  )
  (func (export "ref_is_i31") (param $i i32) (result i32)
    (ref.is_i31 (table.get (local.get $i)))
  )
  (func (export "ref_is_data") (param $i i32) (result i32)
    (ref.is_data (table.get (local.get $i)))
  )
  (func (export "ref_is_func") (param $i i32) (result i32)
    (ref.is_func (table.get (local.get $i)))
  )
)

(invoke "init" (ref.extern 0))

(assert_return (invoke "ref_is_null" (i32.const 0)) (i32.const 1))
(assert_return (invoke "ref_is_null" (i32.const 1)) (i32.const 0))
(assert_return (invoke "ref_is_null" (i32.const 2)) (i32.const 0))
(assert_return (invoke "ref_is_null" (i32.const 3)) (i32.const 0))
(assert_return (invoke "ref_is_null" (i32.const 4)) (i32.const 0))
(assert_return (invoke "ref_is_null" (i32.const 5)) (i32.const 0))
(assert_return (invoke "ref_is_null" (i32.const 6)) (i32.const 0))

(assert_return (invoke "ref_is_i31" (i32.const 0)) (i32.const 0))
(assert_return (invoke "ref_is_i31" (i32.const 1)) (i32.const 1))
(assert_return (invoke "ref_is_i31" (i32.const 2)) (i32.const 0))
(assert_return (invoke "ref_is_i31" (i32.const 3)) (i32.const 0))
(assert_return (invoke "ref_is_i31" (i32.const 4)) (i32.const 0))
(assert_return (invoke "ref_is_i31" (i32.const 5)) (i32.const 0))
(assert_return (invoke "ref_is_i31" (i32.const 6)) (i32.const 0))

(assert_return (invoke "ref_is_data" (i32.const 0)) (i32.const 0))
(assert_return (invoke "ref_is_data" (i32.const 1)) (i32.const 0))
(assert_return (invoke "ref_is_data" (i32.const 2)) (i32.const 1))
(assert_return (invoke "ref_is_data" (i32.const 3)) (i32.const 1))
(assert_return (invoke "ref_is_data" (i32.const 4)) (i32.const 0))
(assert_return (invoke "ref_is_data" (i32.const 5)) (i32.const 0))
(assert_return (invoke "ref_is_data" (i32.const 6)) (i32.const 0))

(assert_return (invoke "ref_is_func" (i32.const 0)) (i32.const 0))
(assert_return (invoke "ref_is_func" (i32.const 1)) (i32.const 0))
(assert_return (invoke "ref_is_func" (i32.const 2)) (i32.const 0))
(assert_return (invoke "ref_is_func" (i32.const 3)) (i32.const 0))
(assert_return (invoke "ref_is_func" (i32.const 4)) (i32.const 1))
(assert_return (invoke "ref_is_func" (i32.const 5)) (i32.const 0))
(assert_return (invoke "ref_is_func" (i32.const 6)) (i32.const 0))
